@extends('layouts.admin-app')

@section('content')

    <div class="contentpanel panel-email">

        <div class="row">

            <div class="col-sm-9 col-lg-12">

                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">添加病人</h4>
                    </div>

                    <form class="form-horizontal form-bordered" action="{{ route('admin.bingren.store') }}" method="POST">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="type" value="{{ $data['type'] }}">
                        <div class="panel-body panel-body-nopadding">
                            @include('admin.bingren._form')
                        </div><!-- panel-body -->

                        <div class="panel-footer">
                            <div class="row">
                                <div class="col-sm-6 col-sm-offset-3">
                                    <button class="btn btn-primary">保存</button>
                                </div>
                            </div>
                        </div><!-- panel-footer -->

                    </form>
                </div>

            </div><!-- col-sm-9 -->

        </div><!-- row -->

    </div>
@endsection


@section('javascript')
    @parent
    <script type="text/javascript">

        $('.bingqu_list').on('change',function () {
            var bingqu_id = $(this).val();
            console.log(bingqu_id);

// ajax通过数据库获取数据
            $.ajax({
                url:"{{url('/admin/bingren/get_bingchuang')}}",
                type:'GET',
                data:{bingqu_id:bingqu_id},
                success:function(data){
                    console.log(data);
                    $('.bingchuang_list').empty();
                    $(".bingchuang_list").prepend("<option value='0'>请选择病床</option>");
                    if(data.code == 0){
                        obj = data.data;
                        for(var p in obj){
                            $(".bingchuang_list").append("<option value="+obj[p].id+">"+obj[p].code+"</option>");
                        }
                    }
                },
                dataType:'json',
            })
        })


    </script>

@endsection